package com.example.kotlinstudy.基本语法

fun main() {
    //集合迭代
    val items = listOf("apple", "banana", "kiwifruit")
    for (item in items) {
        println(item)
    }
    //in判断是否在集合内
    when {
        "orange" in items -> println("juicy")
        "apple" in items -> println("apple is fine too")
    }
    //过滤排序映射
    val fruits = listOf("banana", "avocado", "apple", "kiwifruit")
    fruits.filter { it.startsWith("a") }
        .map { it.uppercase() }
        .sortedBy { it }
        .forEach { println(it) }
}

//printProduct("6", "7")
//printProduct("a", "7")
//printProduct("a", "b")
//fun parseInt(str: String): Int? {
//    return str.toIntOrNull()
//}
//
//fun printProduct(arg1: String, arg2: String) {
//    val x = parseInt(arg1)
//    val y = parseInt(arg2)
//    if (x != null && y != null) {
//        println(x * y)
//    } else {
//        println("'$arg1' or '$arg2' is not a number")
//    }
//}